<template>
  <div class="app-container">
    <el-form>
      <el-col :span="7">
        <el-form-item label-width="104px" label="检查计划名称:" class="postInfo-container-item">
          <el-input placeholder="请输入内容" v-model="query.planName"></el-input>
        </el-form-item>
      </el-col>
      
      <el-col :span="2">
        <el-button type="primary" icon="el-icon-search" style="margin-left:20px">查询</el-button>
      </el-col>
    </el-form>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column align="center" label="序号" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="250px" label="检查计划名称">
        <template slot-scope="{row}">
          <router-link :to="'/message/edit/'+row.id" class="link-type">
            <span>{{ row.planName }}</span>
          </router-link>
        </template>
      </el-table-column>

      <el-table-column width="160px" align="center" label="检查目标">
        <template slot-scope="scope">
          <span>{{ scope.row.target }}</span>
        </template>
      </el-table-column>

      <el-table-column width="150px" align="center" label="所属单位">
        <template slot-scope="scope">
          <span>{{ scope.row.unit }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="计划类型">
        <template slot-scope="scope">
          <span>{{ scope.row.planType }}</span>
        </template>
      </el-table-column>

      <el-table-column class-name="status-col" label="开始时间" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.beginTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>

      <el-table-column class-name="status-col" label="结束时间" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.endTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>

      <el-table-column width="90px" align="center" label="任务状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state }}</span>
        </template>
      </el-table-column>      

      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <router-link :to="'/message/edit/'+scope.row.id">
            <el-button type="text" size="small">生成执行任务</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { fetchList } from '@/api/task'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'TaskList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      query: {
        planName: '', //计划名称
        target: '', //目标
        unit: '', //单位
        state: '', //任务状态、              
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then((response) => {
        this.list = response.data.items
        this.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped  lang="scss" >
@import '~@/styles/mixin.scss';
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
.pagination-container {
  padding: 0;
}
.createPost-container {
  position: relative;

  .createPost-main-container {
    padding: 40px 45px 20px 50px;

    .postInfo-container {
      position: relative;
      @include clearfix;
      margin-bottom: 10px;

      .postInfo-container-item {
        float: left;
      }
    }
  }

  .word-counter {
    width: 40px;
    position: absolute;
    right: 10px;
    top: 0px;
  }
}
</style>
